package com.eudon.design_pattern.behavioral.state.normal;

import com.eudon.design_pattern.behavioral.state.normal.mario_state.Event;
import com.eudon.design_pattern.behavioral.state.normal.mario_state.MarioState;

/**
 * @author eudon
 * @description 马里奥状态机
 * @date 2025/9/3
 * @email syd19970616@gmail.com
 * @address <a href="https://gitee.com/eudon">Gitee</a>
 */
public class MarioStateMachine {
    private MarioState marioState;
    private int score;

    public MarioStateMachine(MarioState marioState) {
        this.marioState = marioState;
        this.score = 0;
    }

    public void eventExecute(Event event) {
        switch (event) {
            case GET_MUSH_ROOM: {
                if (marioState == MarioState.SMALL) {
                    score = score + 100;
                    marioState = MarioState.SUPER;
                }
                break;
            }
            case GET_CAPE: {
                if (marioState == MarioState.SMALL || marioState == MarioState.SUPER) {
                    score = score + 200;
                    marioState = MarioState.CAPE;
                }
                break;
            }
            case GET_FIRE: {
                if (marioState == MarioState.SMALL || marioState == MarioState.SUPER
                        || marioState == MarioState.CAPE) {
                    score = score + 300;
                    marioState = MarioState.FIRE;
                }
                break;
            }
            case MEET_MONSTER: {
                if (marioState == MarioState.SUPER) {
                    score = score - 100;
                } else if (marioState == MarioState.CAPE) {
                    score = score - 200;
                } else if (marioState == MarioState.FIRE) {
                    score = score - 300;
                }
                marioState = MarioState.SMALL;
            }
        }
    }

    public int getScore() {
        return score;
    }

    public MarioState getMarioState() {
        return marioState;
    }
}
